<%--
  Created by IntelliJ IDEA.
  User: Tyranty
  Date: 2017/7/20 0020
  Time: 下午 5:12
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>购物车</title>

    <link rel="shortcut icon" href="${path}/images/favicon.ico">
    <link href="${path}/css/bootstrap.min.css" rel="stylesheet">
    <link href="${path}/css/common.css" rel="stylesheet" type="text/css">
    <link href="${path}/css/style.css" rel="stylesheet" type="text/css">
    <link href="${path}/css/cart.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="${path}/js/jquery-1.11.0.min.js"></script>
    <script type="text/javascript" src="${path}/js/cart.js"></script>


</head>
<body>
<!--添加头部-->
<%@include file="common/header.jsp" %>

<hr>
<input type="hidden" value="${path}" id="path"/>

<!--中部开始-->
<div class="cart w-750">
    <div class="cart-filter-bar pt-50">
        <div class="mycart">
            <p class="pull-left" style="color: green;font-size: 25px">我的购物车</p>
            <img src="${path}/images/icons.png">
            <a href="${path}/product/index" class="pull-right">继续逛逛></a>
        </div>
    </div><x></x>
    <div class="cartmain cartspage">
        <div class="cart-head clearfix">
            <div class="cart-select pull-left">
            </div>
            <input type="hidden">
            <div class="cart-good pull-left">
                <span>商品</span>
            </div>
            <div class="cart-spec pull-left">
                <span>规格</span>
            </div>
            <div class="cart-price pull-left">
                <span>单价(元)</span>
            </div>
            <div class="cart-number pull-left">
                <span>数量</span>
            </div>
            <div class="cart-sum pull-left">
                <span>原价(元)</span>
            </div>
            <div class="cart-action pull-left">
                <span>操作</span>
            </div>
        </div>
        <c:forEach items="${iShoppingCart.items}" var="items">
            <div class="cart-order clearfix ">
                <div class="cartbox clearfix">
                    <input type="hidden" value="${items.value.itemId}" name="itemId">
                    <div class="cartorder-select pull-left clearfix">
                    </div>
                    <div class="cart-imgs pull-left">
                        <a href="${path}/product/details2?pNo=${items.value.pNo}">
                            <img src="${path}/images/product/${items.value.imgUrl}">
                        </a>
                    </div>
                    <div class="cart-name pull-left">
                        <p>
                            <a href="${path}/product/details2?pNo=${items.value.pNo}">${items.value.pName}</a>
                        </p>
                    </div>
                    <div class="spec-num pull-left">
                        <p>${items.value.standard}</p>
                    </div>
                    <div class="price-singular pull-left">
                        <p>￥${items.value.price}</p>
                    </div>
                    <div class="num_sel_lage cart-goods pull-left clearfix">
                        <span  class="min num pull-left">-</span>
                        <input name="number" class="pull-left" type="text" disabled=""
                               value="${items.value.count}">
                        <span  class="add num pull-left">+</span>
                    </div>
                    <div class="sum pull-left">
                        <p>￥${items.value.price}</p>
                    </div>
                    <div class="delete pull-left">
                        <p class="m-cartlist-delete"><a href="${path}/cart/delete?itemId=${items.value.itemId}"><span class="btn btn-success">删除</span></a></p>
                    </div>
                </div>
                <div class="cl"></div>
                <div class="cl"></div>
            </div>
        </c:forEach>
        <!-- 尾部 -->
        <div class="cartfooter clearfix">
            <div class="cart-pay pull-right">
					<span>
                    已选择
                    <em id="spcount">${iShoppingCart.count}件</em>
                    商品  |  订单金额
                </span>
                <span class="all-order" id="sptotal">￥${iShoppingCart.total}</span>
                <a href="${path}/cart/confirm" class="go-pay">去结算</a>
            </div>
            <div class="cl"></div>
        </div>
    </div>
</div>

<hr>

<!--添加尾部-->
<%@include file="common/footer.jsp" %>

<script>
    $(function () {
        var path = document.getElementById("path").value;


        $(".add").click(function () {
            var t = this.previousElementSibling;
            t.value=parseInt(t.value)+1;
            if (parseInt(t.value) <= 1) {
                t.value=1;
            }
            var xmlhttp = new XMLHttpRequest();
            xmlhttp.onreadystatechange = function () {
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                    var arr = xmlhttp.responseText.split(":");
//                    alert(arr)
                    $("#spcount").html(arr[0]+"件");
                    $("#sptotal").html("￥" + arr[1]);
                }
            }
            var itemId =this.parentNode.parentNode.childNodes[1].value;
            xmlhttp.open("get", path + "/cart/modify?count=" + t.value+"&itemId="+itemId);
                xmlhttp.send();
            })


        $(".min").click(function () {

            var t = this.nextElementSibling;
            t.value=parseInt(t.value)-1;
                if (parseInt(t.value) <= 1) {
                    t.value=1;
                }
                var xmlhttp = new XMLHttpRequest();
                xmlhttp.onreadystatechange = function () {
                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                        var arr = xmlhttp.responseText.split(":");
                        $("#spcount").html(arr[0]+"件");
                        $("#sptotal").html("￥" + arr[1]);
                    }
                }
                var itemId =this.parentNode.parentNode.childNodes[1].value;
                xmlhttp.open("get", path + "/cart/modify?count=" + t.value+"&itemId="+itemId);
                xmlhttp.send();
            })
    })
</script>

</body>
</html>
